﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using UniversityManagementSystem.DAL;

namespace UniversityManagementSystem.UI
{
    public partial class ViewResult : System.Web.UI.Page
    {
        Student aStudent = new Student();
        Course course = new Course();
        List<Course> allCourses = new List<Course>();
        List<Course> completedCourses = new List<Course>();
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void SearchButton_Click(object sender, EventArgs e)
        {
            int noOfCompleted = 0;
            double totalCredit = 0;
            double completedCredit = 0;
            try
            {
                aStudent = aStudent.SearchAstudent(regNoTextBox.Text);
                ViewState["aStudent"] = aStudent;
                nameTextBox.Text = aStudent.name;
                emailTextBox.Text = aStudent.email;
                departmentTextBox.Text = aStudent.departmentName;

                allCourses = course.GetAllEnrolledCourses(aStudent.RegistrationNo);
                noOfEnrolledCoursesTextBox.Text = allCourses.Count.ToString();
                completedCourses = aStudent.CompletedCourses(allCourses);
                noOfCompletedCoursesTextBox.Text = completedCourses.Count.ToString();
                noOfRemainingCoursesTextBox.Text = (allCourses.Count - completedCourses.Count).ToString();
                totalCredit = aStudent.CountTotalCredit(allCourses);
                totalCreditTextBox.Text = totalCredit.ToString();
                completedCredit = aStudent.CountCompletedCredit(completedCourses);
                completedCreditTextBox.Text = completedCredit.ToString();
                ramainingTextBox.Text = (totalCredit - completedCredit).ToString();
                detailsResultGridView.DataSource = allCourses;
                detailsResultGridView.DataBind();
            }
            catch (Exception exception)
            {
                messageLabel.Text = "Unable to find student,try again later.";
                messageLabel.ForeColor = System.Drawing.Color.Red;
            }
        }
    }
}